package actionHandlers;

import java.awt.event.*;
import xml.*;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.*;
import palette.CanvasManager;
import palette.CanvasWindow;

public class OpenHandler implements ActionListener {
	
	public void actionPerformed(ActionEvent arg0) {		
		JFileChooser chooser = new JFileChooser(new File(System.getProperty("user.dir")));
	    FileNameExtensionFilter filter = new FileNameExtensionFilter(
	        "XML Documents", "xml");
	    chooser.setFileFilter(filter);
	    
	    if(chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
	    	CanvasManager.getInst().addNewCanvas(chooser.getName(chooser.getSelectedFile()));
	    	CanvasWindow temp = (CanvasWindow)(CanvasManager.getInst().getSelectedFrame());
	    	(new XmlReader()).read(chooser.getName(chooser.getSelectedFile()));
	      	temp.getCanvas().repaint();
	    }
	}

}
